package fr.efrei.musicpliz.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

@Entity
@DiscriminatorColumn(name = "TypeCompte")
@SuppressWarnings("serial")
@Table(uniqueConstraints = @UniqueConstraint(columnNames="mail"))
public class Compte extends AbstractEntity {

	private String nom;
	
	private String adresse;
	
	private int codePostal;
	
	private String ville;
	
	private String numero;
	
	private String mail;
	
	private String password;
	
	private Date naissance;
	
	@OneToMany(mappedBy="client", cascade=CascadeType.ALL)
	private List<Photo> photos;

	@OneToMany(mappedBy="compte", cascade=CascadeType.ALL)
	private List<Authority> authorities;
	
	@OneToMany(mappedBy="compte", cascade=CascadeType.ALL)
	private List<Message> messages;
	
	@OneToMany(mappedBy="expediteur", cascade=CascadeType.ALL)
	private List<Message> sentMessages;
	
	@OneToMany(mappedBy="destinataire", cascade=CascadeType.ALL)
	private List<Message> receivedMessages;
	
	
	public Compte() {
		// Empty constructor (for example for generic search)
	}

	public Compte(String nom, String adresse, int codePostal, String ville,
			String numero, String mail, String password, Date naissance) {
		this.nom = nom;
		this.adresse = adresse;
		this.codePostal = codePostal;
		this.ville = ville;
		this.numero = numero;
		this.mail = mail;
		this.password = password;
		this.naissance = naissance;
		photos = new ArrayList<Photo>();
		authorities = new ArrayList<Authority>();
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) {
		this.nom = nom;
	}

	public String getAdresse() {
		return adresse;
	}

	public void setAdresse(String adresse) {
		this.adresse = adresse;
	}

	public int getCodePostal() {
		return codePostal;
	}

	public void setCodePostal(int codePostal) {
		this.codePostal = codePostal;
	}

	public String getVille() {
		return ville;
	}

	public void setVille(String ville) {
		this.ville = ville;
	}

	public String getNumero() {
		return numero;
	}

	public void setNumero(String numero) {
		this.numero = numero;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getNaissance() {
		return naissance;
	}

	public void setNaissance(Date naissance) {
		this.naissance = naissance;
	}

	public List<Photo> getPhotos() {
		return photos;
	}

	public void setPhotos(List<Photo> photos) {
		this.photos = photos;
	}

	public List<Authority> getAuthorities() {
		return authorities;
	}
	
	public void setAuthorities(List<Authority> authorities) {
		this.authorities = authorities;
	}
	
	public List<Message> getSentMessages() {
		return sentMessages;
	}
	
	public void setSentMessages(List<Message> sentMessages) {
		this.sentMessages = sentMessages;
	}
	
	public List<Message> getReceivedMessages() {
		return receivedMessages;
	}
	
	public void setReceivedMessages(List<Message> receivedMessages) {
		this.receivedMessages = receivedMessages;
	}
	
	public List<Message> getMessages() {
		return messages;
	}
	
	public void setMessages(List<Message> messages) {
		this.messages = messages;
	}

	@Transient
	public String getCompteString() {
		return "Compte";
	}
}
